package com.aftersale.platform.mapper;

import com.aftersale.platform.entity.Announcement;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AnnouncementMapper {

    @Select("SELECT id, title, content, publish_date, created_at FROM announcements ORDER BY publish_date DESC")
    List<Announcement> findAll();

    @Select("SELECT id, title, content, publish_date, created_at FROM announcements WHERE id = #{id}")
    Announcement findById(Integer id);

    @Insert("INSERT INTO announcements (title, content, publish_date) VALUES (#{title}, #{content}, #{publishDate})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(Announcement announcement);

    @Update("UPDATE announcements SET title = #{title}, content = #{content}, publish_date = #{publishDate} WHERE id = #{id}")
    void update(Announcement announcement);

    @Delete("DELETE FROM announcements WHERE id = #{id}")
    void delete(Integer id);
}